package com.wn.web;

import com.wn.annotation.RequireRoles;
import com.wn.auth.JWTUtil;
import com.wn.common.Const;
import com.wn.common.PageParam;
import com.wn.ov.DrugRecordOv;
import com.wn.ov.UserOv;
import com.wn.pojo.CostDrug;
import com.wn.pojo.Drug;
import com.wn.resopnse.ServerResponse;
import com.wn.service.CostService;
import com.wn.service.PharmacyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 药房管理
 */
@Api(value = " 药房管理裂口",description=" 药房管理接口")
@RestController
@RequestMapping("drug")
public class PharmacyController {

    @Autowired
    private PharmacyService pharmacyService;

    @Autowired
    private CostService costService;


    /** 获取药品列表 */
    @PostMapping("get-durgList")
    @RequireRoles(roles = "medical")
    @ApiOperation("获取药品列表")
    public ServerResponse getDrugList(@RequestHeader("token")String token,
                                      @RequestBody PageParam<Drug> pageParam){
        return pharmacyService.getDrugList(pageParam);
    }

    /** 新增药品 */
    @PostMapping("add-drug")
    @RequireRoles(roles = "medical")
    @ApiOperation("新增药品")
    public ServerResponse addDrug(@RequestHeader("token")String token,@RequestBody @Validated Drug drug){
        //System.out.println(drug);
        return pharmacyService.addDrug(drug);
    }

    /** 修改药品 */
    @PostMapping("update-drug")
    @RequireRoles(roles = "medical")
    @ApiOperation("修改药品")
    public ServerResponse updateDrug(@RequestHeader("token")String token,@RequestBody @Validated Drug drug){
        //System.out.println(drug);
        return pharmacyService.updateDrug(drug);
    }

    /** 删除药品 */
    @PostMapping("delete-drug")
    @RequireRoles(roles = "medical")
    @ApiOperation("删除药品")
    public ServerResponse deleteDrug(Integer id){
        return pharmacyService.deleteDrug(id);
    }


    //使用药品的记录
    @PostMapping("getDrugRecordOvList")
    @RequireRoles(roles = "medical")
    @ApiOperation("获取药品列表")
    public ServerResponse getDrugRecordOvList(@RequestHeader("token")String token,
                                      @RequestBody PageParam<DrugRecordOv> pageParam){
        return pharmacyService.getDrugRecordOvList(pageParam);
    }


    //审核成功出单
    @PostMapping("updateDrugStatus1")
    @RequireRoles(roles = "medical")
    public ServerResponse updateDrugStatus1(@RequestHeader("token") String token,@RequestBody CostDrug costDrug){
        UserOv userOv = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return costService.updateDrugStatus1(costDrug,userOv.getId());
    }

    //取消审核出单
    @PostMapping("updateDrugStatus2")
    @RequireRoles(roles = "medical")
    public ServerResponse updateDrugStatus2(@RequestHeader("token") String token,@RequestBody CostDrug costDrug){
        return costService.updateDrugStatus2(costDrug);
    }
}
